package cc.magicjson.mall.eureka.interfaces.configurer.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OpenApiConfig {

    @Bean
    public OpenAPI customOpenAPI(@Value("${springdoc.info.title}") String title,
                                 @Value("${springdoc.info.description}") String description,
                                 @Value("${springdoc.info.version}") String version,
                                 @Value("${springdoc.info.terms-of-service}") String termsOfService,
                                 @Value("${springdoc.info.contact.name}") String contactName,
                                 @Value("${springdoc.info.contact.email}") String contactEmail,
                                 @Value("${springdoc.info.contact.url}") String contactUrl,
                                 @Value("${springdoc.info.license.name}") String licenseName,
                                 @Value("${springdoc.info.license.url}") String licenseUrl) {
        return new OpenAPI()
                .info(new Info()
                        .title(title)
                        .description(description)
                        .version(version)
                        .termsOfService(termsOfService)
                        .contact(new Contact().name(contactName).email(contactEmail).url(contactUrl))
                        .license(new License().name(licenseName).url(licenseUrl)));
    }
}